package com.kyc.kycxkplaygame;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import com.kyc.kycxkplaygame.dbutils.IntImp.ConfigureManager;
import com.kyc.kycxkplaygame.dbutils.IntImp.RetrofitUtils;
import com.kyc.kycxkplaygame.greendao.gen.DaoMaster;
import com.kyc.kycxkplaygame.greendao.gen.DaoSession;
import com.kyc.kycxkplaygame.util.HttpApiConst;

/**
 * Created by Administrator on 2018/7/4.
 */

public class PlayGameApplication extends Application {
    public static Context context;
    private static PlayGameApplication instance;
    private DaoMaster.DevOpenHelper mHelper;
    private SQLiteDatabase db;
    private DaoMaster mDaoMaster;
    private DaoSession mDaoSession;

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
        instance = this;
        setDatabase();
        ConfigureManager.getConfigureManager().setOkhttpCache(true);//设置okhttp是否缓存
        RetrofitUtils.initRetrofit(HttpApiConst.kycxkBaseDomain);

    }

    public static PlayGameApplication getInstance() {
        if (instance == null) {
            throw new NullPointerException("WinApplication instance is null, please register in AndroidManifest.xml first");
        }
        return instance;
    }

    /**
     * 获取上下文
     *
     * @return Context
     */
    public static Context getContext() {
        return context;
    }

    private void setDatabase() {
        mHelper = new DaoMaster.DevOpenHelper(this,"Summer_llk.db",null);
        db = mHelper.getWritableDatabase();
        mDaoMaster = new DaoMaster(db);
        mDaoSession = mDaoMaster.newSession();
    }


    public DaoSession getDaoSession() {
        return mDaoSession;
    }
}
